<template>
	<div>
		<el-form :inline="true" ref="form" :model="pageAbout">
            <el-form-item label="企业名称" prop="enterprise_name">
                <el-input placeholder="企业名称" v-model="pageAbout.enterprise_name"></el-input>
            </el-form-item>
            <el-form-item label="企业类型" prop="enterprise_type">
                <el-select v-model="pageAbout.enterprise_type">
                    <el-option :label="item.name" :value="item.id" v-for="item in ComtypeMessage"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="上市情况" prop="is_list">
                <el-select v-model="pageAbout.is_list">
                    <el-option :label="item.name" :value="item.id" v-for="item in shMessage"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="启用状态" prop="status">
                <template>
                    <el-select v-model="pageAbout.status" placeholder="请选择">
                        <el-option label="是" value="2"></el-option>
                        <el-option label="否" value="1"></el-option>
                    </el-select>
                </template>
            </el-form-item>
            <el-form-item label="涉及领域" prop="involve_field">
                <!--<el-select v-model="form.field0Id" size="small" style="width:120px" @change="change()">-->
                <!--<el-option :label="item.name" :value="item.id" v-for="item in form.involvedfieldList0" :key="item.value" >-->
                <!--</el-option>-->
                <!--</el-select>-->
                <!--</el-form-item>-->
                <!--<el-form-item  prop="field1Id">-->
                <!--<el-select v-model="form.field1Id" size="small" style="width:120px" @change="changeThree()" v-if="form.secondLevel.length">-->
                <!--<el-option :label="item.name" :value="item.id" v-for="item in form.secondLevel"></el-option>-->
                <!--</el-select>-->
                <!--</el-form-item>-->
                <!--<el-form-item  prop="field2Id">-->
                <!--<el-select v-model="form.field2Id" size="small" style="width:120px" v-if="form.secondLevel.length&&form.thirdLevel.length">-->
                <!--<el-option :label="item.name" :value="item.id" v-for="item in form.thirdLevel"></el-option>-->
                <!--</el-select>-->
                <el-select v-model="pageAbout.involve_field">
                    <el-option :label="item.name" :value="item.id" v-for="item in LyMessage"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="客户经理" prop="account_manager_id">
                <el-select v-model="pageAbout.account_manager_id">
                    <el-option :label="item.realName" :value="item.id" v-for="item in JlMessage"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="resetForm('form')">重置</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="found">查找</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="openDialog('addcompanyDialog')" v-if="limit.limitId58.status==1">新增</el-button>
            </el-form-item>
        </el-form>
        <div>
            <div class="dateMsg" v-if="pageCount" style="color: red">总计<b>{{pageCount}}</b>条数据</div>
            <el-table :data="tableData" style="width: 100%" v-loading="listLoading">
                <el-table-column prop="enterprise_name" label="名称">
                </el-table-column>
                <el-table-column prop="enterprise_type" label="类型">
                </el-table-column>
                <el-table-column prop="is_list" label="上市情况">
                </el-table-column>
                <el-table-column prop="involve_field" label="涉及领域" :formatter="banFormatLength">
                </el-table-column>
                <!--<el-table-column prop="date" label="能力项">-->
                <!--</el-table-column>-->
                <el-table-column prop="status" label="启用/禁用" :formatter="banFormat">
                </el-table-column>
                <el-table-column prop="account_manager" label="客户经理">
                </el-table-column>
                <el-table-column prop="date" label="操作">
                    <template scope="scope">
                        <el-button  type="text" size="small" @click="changeMan('changeUserDialog',scope.row.enterprise_id)" v-if="limit.limitId57.status==1">变更客户经理</el-button>
                        <el-button type="text" size="small" @click="editcomDialog('editDialog',scope.row.enterprise_id)" v-if="limit.limitId55.status==1">编辑</el-button>
                        <el-button v-if="scope.row.status==1" type="text" size="small" @click="forBidden(scope.row.enterprise_id,2)">启用</el-button>
                        <el-button v-else type="text" size="small" @click="forBidden(scope.row.enterprise_id,1)">禁用</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="pagination" style="width:200px;margin-top:10px;margin-left:75% ">
            <el-pagination layout="prev, pager, next"  :total='pageCount' @current-change="getCurrentpage" :page-size=10></el-pagination>
        </div>
        <!-- 变更客户经理 -->
        <el-dialog title="变更客户经理" :visible.sync="dialog.changeUserDialog.open" size="tiny" v-if="dialog.changeUserDialog.open">
        <el-form>
            <el-form-item label="客户经理选择">
                <el-select v-model="user_id" placeholder="请选择客户经理">
                    <el-option v-for="item in JlMessage" :label="item.realName" :value="item.id" :key="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <div style="text-align:center">
                    <el-button type="primary" @click="closeDialog('changeUserDialog')">取消</el-button>
                    <el-button type="primary" @click="changManager('changeUserDialog')">提交</el-button>
                </div>
            </el-form-item>
        </el-form>
    </el-dialog>
        <!--编辑企业信息-->
        <el-dialog title="编辑企业信息" :visible.sync="dialog.editDialog.open" size="small" v-if="dialog.editDialog.open" :modal="false">
            <editCompany></editCompany>
        </el-dialog>
        <!--新增企业-->
        <el-dialog title="新增企业" :visible.sync="dialog.addcompanyDialog.open" size="small" v-if="dialog.addcompanyDialog.open" :modal="false">
            <addCompany></addCompany>
        </el-dialog>
        <!--关系网-->
	</div>
</template>
<script>
    import Bus from '@/config/bus.js'
    import _http from '@/components/common/http.vue'
    import _param from '@/components/common/param.vue'
//    import compEdit from '@/components/working/common/compEdit.vue'
    import addCompany from '@/components/cust/company/add.vue'
    import editCompany from '@/components/cust/company/edit.vue'
export default{
    components:{addCompany,editCompany},
	data(){
		return{
            apiPort:{
//                    列表页内容接口
                contentApi:"original/enterprise/commonSearch",
//                企业类型字典接口
                companytypeApi:'diction/getEnterpriseType',
//                    #上市情况字典接口
                inmarketApi:'diction/getEnterpriseType',
//                    涉及领域字典接口
                involvedfieldApi:'diction/getEnterpriseType',
//                    客户经理字段接口
                customerManager:'sysuser/v1/selectAccountmanager',
//                改变客户经理
                changeMan:'original/enterprise/changeManager',
//                变更状态
                statusC:'original/enterprise/jinyong'
            },
            value:[],
            options:[],
            position:'left',
            form:{
                //企业类型接口字典
                companyTypelist:'',
//                上市情况接口参数
                inmarketList:'',
//                涉及领域参数
                involvedfieldList0:'',
                involvedfieldList1:'',
                involvedfieldList2:'',
//                涉及领域中间层级
                secondLevel:[],
//                涉及领域第三层级
                thirdLevel:[],
                flag:false,
                name: '',
                region: '',
//                    企业类型id
                companyId: '',
//                    上市情况id
                inmarketId:'',
//                    涉及领域一级id
                field0Id: '',
//                    涉及领域二级id
                field1Id: '',
//                    涉及领域三级id
                field2Id: '',
                changeUser:{
                    user:''
                },
                search:{
                    name:'',
                    techRoute:'-1',
                    user:''
                }
            },
            initData:{
                userList:[],
                techRoute:[]
            },
            dialog:{
                addcompanyDialog:{
                    open:false
                },
                changeUserDialog:{
                    open:false
                },
                editDialog:{
                    open:false
                },
                linkNet:{
                    open:true
                }
            },

            pageAbout:{
                enterprise_type:'',
                is_list:'',
                involve_field:'',
                status:'',
                account_manager_id:'',
                enterprise_name:'',
                pageNumber:1,
                pageSize:10
            },
            currentPage:'',
            pageCount:'',
            listLoading:false,
			tableData: [],
            ComtypeMessage:"",
            shMessage:'',
            LyMessage:"",
            JlMessage:'',
            changeManageid:'',
            userid:'',
            user_id:'',
            editComid:'',
            limit:''
		}
	},
    beforeDestroy(){
        Bus.$off("closeA")
        Bus.$off("closeB")
    },
    mounted(){
        this.limit = JSON.parse(localStorage.getItem("limitList"))
        this.userid=localStorage.getItem('userId')
        this.pageAbout.userid = localStorage.getItem('userId')
        this.getTotal()
        this.getDicdata()
        var that = this
        Bus.$on('closeA',function(val){
            if(val==1){
                setTimeout(function(){
                    console.log(1234)
                    that.closeDialog('addcompanyDialog')
//
                },200)
            }
        })
        Bus.$on('closeB',function(val){
            if(val==1){
                setTimeout(function(){
                    console.log(1234)
                    that.closeDialog('editDialog')
//                    that.closeDialog('addLinkman')
                },200)
            }
        })
//        this.getType()
//        this.test()
    },
    methods:{
//        企业编辑
        editcomDialog(dialog,id){
            this.editComid=id
            this.openDialog(dialog)
            setTimeout(function(){
                Bus.$emit('editFlag',id)
            },200)
        },
//        启用禁用
        forBidden(id,par){
            var that = this
            var param = {enterpriseid:id,status:par,userid:that.userid}
            var params = that.querystring.stringify(param)
            _http.axiosRequest(that,that.apiPort.statusC,params,(res)=>{
            console.log(res.data)
            that.getCurrentpage(that.currentPage)
            that.closeDialog(param)
        })
        },
        getDicdata(){
            var that = this
            //            获取企业类型接口
            var paramCom={code:"qylx",userid:that.userid}
            var paramsCom = that.querystring.stringify(paramCom)
            _http.axiosRequest(that,that.apiPort.companytypeApi,paramsCom,(res)=>{
                that.ComtypeMessage=res.data.data
        })
    //上市情况接口
            var paramSh={code:"ssqk",userid:that.userid}
            var paramsSh = that.querystring.stringify(paramSh)
            _http.axiosRequest(that,that.apiPort.inmarketApi,paramsSh,(res)=>{
                that.shMessage=res.data.data
        })
//            涉及领域接口
            var paramLy={code:"sjly",userid:that.userid}
            var paramsLy = that.querystring.stringify(paramLy)
            _http.axiosRequest(that,that.apiPort.involvedfieldApi,paramsLy,(res)=>{
                console.log("sjly")
                console.log(res)
                that.LyMessage=res.data.data
                console.log(that.LyMessage)
        })
//            客户经理接口
            var paramsSh = that.querystring.stringify({userid:that.userid})
            _http.axiosRequest(that,that.apiPort.customerManager,paramsSh,(res)=>{
                that.JlMessage=res.data
                console.log('客户经理')
                console.log(that.JlMessage)
        })
        },
        banFormat:function(row,column){
            var ban = row[column.property];
            if ( ban == 1 ){
                return "禁用";
            }
            return "启用";
        },
        banFormatLength:function(row,column){
            var ban = row[column.property];
            if ( ban.length >10  ){
                return ban.replace(',','||').substring(0,10)+'...' ;
            }
            return ban;
        },
        //跳转到指定页
        getCurrentpage(val){
            this.listLoading=true
            var that = this
            this.currentPage = val ? val:1
            this.pageAbout.pageNumber= this.currentPage
            var params = that.querystring.stringify(this.pageAbout)
            _http.axiosRequest(that,that.apiPort.contentApi,params,(res)=>{
                that.pageCount=res.data.data.total

            this.listLoading=false
            that.tableData = res.data.data.records
        })
        },
//            获取首页数据
        getTotal(){
            this.listLoading=true
            var that = this
            var params = that.querystring.stringify(this.pageAbout)
            _http.axiosRequest(that,that.apiPort.contentApi,params,(res)=>{
                console.log(res.data.data.records)
            that.pageCount=res.data.data.total
            this.listLoading=false
            that.tableData = res.data.data.records
        })
        },
        change(){
            this.form.secondLevel=[]
            for(var a in this.form.involvedfieldList1){
                if(this.form.field0Id==this.form.involvedfieldList1[a].father_id){
                    console.log(this.form.involvedfieldList1[a])
                    this.form.secondLevel.push(this.form.involvedfieldList1[a])
                }
            }
        },
//            涉及领域第三级
        changeThree(){
            this.form.thirdLevel=[]
            for(var a in this.form.involvedfieldList2){
                if(this.form.field1Id==this.form.involvedfieldList2[a].father_id){
                    this.form.thirdLevel.push(this.form.involvedfieldList2[a])
                }
            }
        },
//            获取字典类型接口
        getType(){
            var that = this
//            获取企业类型字典接口
            _http.axiosGet(that,that.apiPort.companytypeApi,(res)=>{
                that.form.companyTypelist=res.L0

        })
//            获取上市情况接口
            _http.axiosGet(that,that.apiPort.inmarketApi,(res)=>{
                that.inmarketList=res.L0
            console.log(that.inmarketList)
        })
//            获取领域接口
            _http.axiosGet(that,that.apiPort.involvedfieldApi,(res)=> {
                that.form.involvedfieldList0 = res.L0
            that.form.involvedfieldList1 = res.L1
            that.form.involvedfieldList2 = res.L2
        })

        },

        //            重置按钮
        resetForm(formName){
            this.currentPage=1
            this.pageAbout={
                userid:this.userid,
                enterprise_type:'',
                        is_list:'',
                        involve_field:'',
                        status:'',
                        account_manager_id:'',
                        enterprise_name:'',
                        pageNumber:1,
                        pageSize:10
            },
            this.$refs[formName].resetFields();
        },
        found(){
            this.pageAbout.pageNumber=1
            this.getTotal()
        },
//        变更客户经理确定
        changManager(param){
            var that = this
            var par = {enterpriseid:this.changeManageid,userid:this.userid,user_id:this.user_id}
            var params = that.querystring.stringify(par)
            _http.axiosRequest(that,that.apiPort.changeMan,params,(res)=>{
                console.log(234567890)
            console.log(res.data)
            that.getCurrentpage(that.currentPage)
            that.closeDialog(param)
        })
        },
//        打开各种对话框
//        打开客户经理编辑页面
        changeMan(dialog,id){
            this.changeManageid=id
            this.openDialog(dialog)
        },
        openDialog(dialog){
            this.dialog[dialog].open = true
        },
        closeDialog(dialog){
            this.dialog[dialog].open = false
        }
    },

}
</script>